<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>

<head>
    <%@ include file="/platform/style.jsp"%>
</head>
<style>
    .winput{
        width: 100px;
    }
    .add{
        color: red;
        text-decoration: none;
    }
    .del{
        color: red;
        text-decoration: none;
        padding-left: 5px;
    }
</style>
<body>
    <div class="headT">
        <span></span>
        <label>新注册积分</label>
    </div>
        <div class="ui-formContent">

            <div>
                <label style="width:130px;text-align:right">
                    <font class="required">*</font>新注册获得积分：</label>

                <input class="new" name="register" value="<w:write bind="bean.register"/>"  styleClass="easyui-validatebox" maxlength="5" autocomplete="off" oninput="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"/>

            </div>

        </div>
    <div class="headT">
        <span></span>
        <label>签到积分</label>
    </div>
        <div class="ui-formContent classintegral">
            <div class="ww">
                <label style="width:130px;text-align:right">每日签到获得：</label>
                <input type="text" class="DayIntegral" value="<w:write bind="bean.today"/>" name="today" maxlength="5" oninput="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
            </div>

            <div class="new">
                <w:define id="info_size" bind="#aaaa"/>
                <w:switch>
                <w:case bind="#info_size.size <= 0">
                    <label style="width:130px;text-align:right">连续：</label>
                    <input type="text" maxlength="1" class="day" name="day" value="<w:write bind="#info.day"/>" oninput="replaceDay(this)" onafterpaste="this.value=this.value.replace(/\D/g,'')">&nbsp;日获得&nbsp;<input type="text" class="winput" name="integral" value="<w:write bind="#info.integral"/>" maxlength="5" oninput="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
                    <a href="javascript:;" class="add" onclick="addweek(this)">[+]</a>
                </w:case>

                <w:case bind="#info_size.size >= 0">
                    <w:iterate id="info" bind="#rulelist" indexId="info_index">
                        <w:switch>
                            <w:case bind="#info_index ==0">
                            <div style='padding: 5px;' class='new'>
                            <label style="width:130px;text-align:right">连续：</label>
                            <input type="text" maxlength="1" class="day" name="day" value="<w:write bind="#info.day"/>" oninput="this.value=this.value.replace(/[^1-7]/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">&nbsp;日获得&nbsp;<input type="text" class="winput" name="integral" value="<w:write bind="#info.integral"/>" maxlength="5" oninput="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
                            <a href="javascript:;" class="add" onclick="addweek(this)">[+]</a>
                            </div>
                            </w:case>
                            <w:else>
                                <div style='padding: 5px;' class='new'>
                                <label style="width:130px;text-align:right">连续：</label>
                                <input type="text" maxlength="1" class="day" name="day" value="<w:write bind="#info.day"/>" oninput="this.value=this.value.replace(/[^1-7]/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">&nbsp;日获得&nbsp;<input type="text" class="winput" name="integral" value="<w:write bind="#info.integral"/>" maxlength="5" oninput="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
                                <a href="javascript:;" class="add" onclick='delweek(this)'>[-]</a>
                                </div>
                            </w:else>
                        </w:switch>
                    </w:iterate>
                </w:case>
            </w:switch>

            </div>
        </div>
    <div class="headT">
        <span></span>
        <label>交易积分</label>
    </div>
        <div class="ui-formContent ">
            <div>
                <label style="width:130px;text-align:right">下单获得积分比例：</label>
                <input type="text" class="" name="scale" value="<w:write bind="bean.scale"/>"  oninput="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">&nbsp;%
            </div>
        </div>
    <div style="width: 100%;  text-align: center;padding: 10px 0;">
        <button href="javascript:;" value="" class="" onclick="AddIntegratlForm();">保存</button>
    </div>
    <script>
        /**
         * 设置积分规则时，限制输入框不可以输入相同天数
         * */
        function replaceDay(obj) {
            var self = $(obj);
            var thisVal = self.val();
            self.val(thisVal.replace(/[^1-7]/g, ''));
            $("input[class^='day']").each(function () {
                if ($(this).attr("class") == self.attr("class"))
                {

                }else if ($(this).val() == self.val() && $(this).val() != "") {
                    self.val("");
                }

            })
        }

        /**
         * 点击+号触发执行
         * @param obj
         */

        function addweek(obj) {

            if ($(".new").length > 8){
                   return false;
            }else {
                var h = "";

                h +="<div style='padding: 5px;' class='new'>"
                h +="<label style='width:130px;text-align:right'>连续：</label>"
                h +="<input type='text' class='day' name='day' value='' maxlength='1' class='winput' oninput=\"this.value=this.value.replace(/[^1-7]/g,'')\" onafterpaste=\"this.value=this.value.replace(/\D/g,'')\">"
                h +="&nbsp;日获得&nbsp;<input maxlength='5' type='text' class='winput' name='integral' value='' oninput=\"this.value=this.value.replace(/\\D/g,'')\" onafterpaste=\"this.value=this.value.replace(/\D/g,'')\" >"
                h +="<a href='javascript:;' class='del' onclick='delweek(this)'>[-]</a>"
                h +="</div>"

                $(obj).parents(".ui-formContent").append(h);
            }
        }
        /**
         * 点击-号触发执行
         * @param obj
         */
        function delweek(obj) {
            $(obj).parent().remove();
        }


        var items = [];
        function AddIntegratlForm() {
                var data= {};
            data["bean.scale"] = $("[name='scale']").val();
            data["bean.register"] = $("[name='register']").val();
            data["bean.today"] = $("[name='today']").val();

             $(".classintegral .new").each(function () {
                 var item = {};
                 item["day"] = $(this).find("[name='day']").val();
                 item["integral"] = $(this).find("[name='integral']").val();
                 items.push(item);
             });

            data["bean.integral"]=JSON.stringify(items);
            console.log(data);


            $w.doUrl(ctx + "/integral/IntegralPage@update.page", data, function (ret) {
                $.messager.progress('close');
                if (ret.state == 'ok') {
                    window.parent.$w.correctMsg("保存积分成功");
                    $w.closeCurrWin("ok");

                } else {
                    pedit_saveing = false;
                    window.parent.$w.alertMsg(ret.state);
                }
            });

        }

    </script>
</body>
